
package sr.codemg.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import sr.codemg.config.JwtConfig;
import sr.codemg.entity.SysButtons;
import sr.codemg.service.SysButtonsService;
import sr.codemg.utils.Constants;
import sr.codemg.vm.Base;
import sr.codemg.vm.Selects;
import sr.codemg.vm.Tables;

import java.util.List;
import java.util.Map;

/**
 * 按钮信息
 **/
@Slf4j
@RestController
@RequestMapping("/sysbuttons")
public class SysButtonsController {

    @Autowired
    SysButtonsService sysButtonsService;

    @GetMapping("/{id}")
    public SysButtons get(@PathVariable("id") String id) {
        return sysButtonsService.get(id);
    }

    @PutMapping
    public Tables list(@RequestBody Map<String, Object> params) {
        return sysButtonsService.findList(params);
    }

    @PostMapping
    public Base.Response post(@RequestBody SysButtons entity) {
        entity.setId(null);
        return sysButtonsService.add(entity);
    }

    @PutMapping("/edit")
    public Base.Response put(@RequestBody SysButtons entity) {
        return sysButtonsService.update(entity);
    }

    @DeleteMapping("/{id}")
    public Base.Response delete(@PathVariable("id") String id) {
        return sysButtonsService.delete(id);
    }

    @PostMapping("/select")
    public Selects.Response select(@RequestBody Selects.Request req) {
        return sysButtonsService.select(req);
    }

    @GetMapping("/array")
    public List<SysButtons> array(String menuKey, @CookieValue(Constants.Authorization) String token) {
        return sysButtonsService.array(menuKey, JwtConfig.thinning(token));
    }
}

